package raphaelMatcher;

public class StringUtil {

	public static String[] split(String s, char c, int initSize) {
		String[] buffer = new String[initSize];
		int numBuffer = 0;
		int start = 0;
		int end;
		
		while ((end = s.indexOf(c, start)) != -1) {
			if (numBuffer >= buffer.length) buffer = extendBuffer(buffer);
			buffer[numBuffer++] = s.substring(start, end);
			start = end + 1;
		}
		if (numBuffer >= buffer.length) buffer = extendBuffer(buffer);
		buffer[numBuffer++] = s.substring(start); 
		
		String[] returnValue = new String[numBuffer];
		System.arraycopy(buffer, 0, returnValue, 0, numBuffer);
		return returnValue;
	}
	
	private static String[] extendBuffer(String[] buffer) {
		String[] newBuffer = new String[2*buffer.length];
		System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
		return newBuffer;
	}
}

